<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.io.*"%>
<html>
<jsp:useBean id="uploadFileForm1" scope="session" class="mypack.form.UploadFileResultForm"/>

<head>
<meta http-equiv="content-Type" contentType="text/html; charset=utf-8">
<%request.setCharacterEncoding("ISO-8859-1"); %>

<title>上传</title>
 <!-- 新 Bootstrap 核心 CSS 文件 -->
			<link rel="stylesheet" href="static/css/bootstrap.min.css">
            <!-- 可选的Bootstrap主题文件（一般不用引入） -->
			<link rel="stylesheet" href="static/css/bootstrap-theme.min.css">

            <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
			<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>

			<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
			<script src="static/js/bootstrap.min.js"></script>
            
            <link href="static/css/homepage.css" rel="stylesheet" type="text/css" />
</head>
<%           
             if(request.getSession().getAttribute("check_code") != null){
%>
<body>
<% uploadFileForm1.setParameters(request, response); %>
<%
InputStream in = null;
FileOutputStream o = null;

 try{
  String temp=(String)request.getSession().getAttribute("check_code");//获得sessionId
  //上传文件的存储路径
  String test = uploadFileForm1.getHname();
  String filename = "F:\\学习\\大三上\\web\\final\\学生作业\\"+"作业_" +"第"+test+"次作业"+ "_"+ temp + ".txt";
  
  out.println("   这是测试结果: "+ test + "    这是测试结果");
  String fn=new String(filename);

  File f1=new File(fn);    
   f1.createNewFile();
  o=new FileOutputStream(f1);                                 //文件输出流指向上传文件所在路径
  
  in = request.getInputStream();                                         //从客户端获得文件输入流
  
  
  InputStreamReader reader = new InputStreamReader (in); 
  
  BufferedReader bufferedReader = new BufferedReader(reader);
  String linetxt;
  while((linetxt = bufferedReader.readLine())!= null){
      linetxt += "\r\n";     
	  o.write(linetxt.getBytes());
          // out.println(linetxt + " \r\n ");
           
  }
  
 
 
  out.println( " 上传成功！ ");
  
  
  o.close();
  in.close();                                                                                                           //关闭输入流和文件输出流
  out.println("<a class='btn btn-primary btn-lg' role='button' href = 'http://localhost:8080/Final/homepage.html' >返回首页</a>");
%>
<script language="javascript">alert("文件上传成功！");</script>
<%
 }catch (Exception e) {
	 out.println("！！~~这是错误原因：  "+e.getMessage());
	  
 } finally {

 
 //in.close();
 //o.close();
 
 
 
 
 }
%>
<%
}
            else{
            	out.print( " <a href='http://localhost:8080/Final/index.jsp'>请登录</a>");
            }
%>